package leetcodecompetition.S117;

/**
 * @Author: Siantar
 * @Date: 2023-11-11-22:40
 * @Description: 1.0
 */
public class T100127 {
    public long distributeCandies(int n, int limit) {
        long res = 0;
        for (int i = 0; i <= limit; i++) {
            int s = n - i;
            if (0 <= s && s <= limit) {
                res += (s + 1);
            } else if (limit < s && s <= 2 * limit) {
                res += 2L * limit - s + 1;
            }
        }
        return res;
    }
}
